/***************************************************************************
* Lyrics-Player                                                            *
* Copyright (C) 2012 Andrey Derevyanko <derandr@gmail.com>                 *
*                                                                          *
* This program is free software: you can redistribute it and/or modify     *
* it under the terms of the GNU General Public License as published by     *
* the Free Software Foundation, either version 3 of the License, or        *
* (at your option) any later version.                                      *
*                                                                          *
* This program is distributed in the hope that it will be useful,          *
* but WITHOUT ANY WARRANTY; without even the implied warranty of           *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
* GNU General Public License for more details.                             *
*                                                                          *
* You should have received a copy of the GNU General Public License        *
* along with this program.  If not, see <http://www.gnu.org/licenses/>.    *
***************************************************************************/

/*! \file HauptWnd.h
 *  \brief The main program window
 *  \details Window implements all the user interface functions
 *  \author Andrey Derevyanko <derandr@gmail.com>
 *  \version 1.0
 *  \date 11/06/2012
 *  \copyright GNU Public License
 */

#ifndef __HAUPT_WND__
#define __HAUPT_WND__

#include <QMainWindow>
#include <QBoxLayout>
#include <QGridLayout>
#include <QTextEdit>
#include <QTreeView>
#include <QDirModel>
#include <QList>
#include <QSplitter>
#include <QModelIndex>
#include <QApplication>
#include <QTime>
#include <QDirIterator>
#include <QFileDialog>

#include <QPushButton>
#include <QAction>
#include <QToolBar>
#include <QHeaderView>
#include <QCloseEvent>
#include <QLabel>
#include <QMenuBar>
#include <QMenu>

#include <QSettings>

#include <phonon/audiooutput.h>
#include <phonon/seekslider.h>
#include <phonon/VolumeSlider>

#include "playListView.h"
#include "trackRecModel.h"
#include "coverInfoWnd.h"

/*! \class HauptWnd
 *  \brief Main program window class
 */
class HauptWnd : public QMainWindow
{
    Q_OBJECT
public:
    //! Constructor
    HauptWnd();
    //! Destructor
    ~HauptWnd();
private:
    /*! \fn void actionsCreate()
     *  \brief Create and set up program actions.
     */
    void actionsCreate();
    /*! \fn void toolBarsCreate()
     *  \brief Fill up program toolbar with actions.
     */
    void toolBarsCreate();
    /*! \fn void mainMenuCreate()
     *  \brief Fill up program menu with actions.
     */
    void mainMenuCreate();
    /*! \fn void loadSettings()
     *  \brief Load program settings that are seved on program close.
     */
    void loadSettings();
    QTextEdit * lyrTextEdit; //!< Lyrics display window
    playListView_t * playListView; //!< Track information from playListModel
    QTreeView * fileTreeView; //!< Hard disk files view
    QDirModel * fileDirModel; //!< Hard disk files model
    TrackRecordModel * playListModel; //!< Track information model
    QSplitter * listSplitter; //!< File list and track list splitter
    QSplitter * mainSplitter; //!< Lists and lyrics splitter
    QAction * playAction; //!< Play/pause
    QAction * stopAction; //!< Stop
    QAction * nextAction; //!< Next track
    QAction * prevAction; //!< Previous track
    QAction * randomAction; //!< Play files randomly
    QAction * closeAction; //!< Close program
    QAction * deleteAction; //!< Delete actual file from the track list
    QAction * burnAction; //!< Clear track list
    QAction * loadAction; //!< Load track list
    QAction * saveAction; //!< Save track list
    QAction * rootSelectAction; //!< Select file tree root
    QAction * aboutProgAction; //!< About program menu item was clicked
    QAction * aboutQtAction; //!< About Qt menu item was clicked
    QToolBar * playToolBar; //!< Program toobar
    Phonon::AudioOutput * playAO; //!< Play device interface
    Phonon::SeekSlider * playSlider; //!< Play slider
    Phonon::VolumeSlider *volumeSlider; //!< Volume slider
    bool isPlaying; //!< Is something playing
    QLabel * totalTimeLabel; //!< Full track time
    QLabel * currTimeLabel; //!< Actual play time
    QLabel * currSongName; //!< Actual track name
    QMenu *fileMenu; //!< File menu
    QMenu *playMenu; //!< Play options menu
    QMenu *optionsMenu; //!< All settings menu
    QMenu *aboutMenu; //!< Miscelanious items menu
    coverInfoWnd *coverInfo; //!< Window displaying cover and detailed info
    QString rootDir; //!< Current file tree root
    QSettings *progSettings; //!< Program settings class
private slots:
    /*! \fn void aboutClicked()
     *  \brief About program menu item clicked.
     *  \details About window is displayed.
     */
    void aboutClicked();
    /*! \fn void aboutQtClicked()
     *  \brief About Qt menu item clicked.
     *  \details About Qt window is displayed.
     */
    void aboutQtClicked() {QApplication::aboutQt();}
public slots:
    /*! \fn void add2Play(const QModelIndex & index)
     *  \brief Add to the list of files to play
     *  \details Interface to the addTrack function from playListModel
     *  \param index Fie path in the file system
     */
    void add2Play(const QModelIndex & index);
    /*! \fn void showLyrics(const QString lyrFileString)
     *  \brief Song lirycs show
     *  \param lyrFileString Path to lyrics file
     */
    void showLyrics(const QString lyrFileString);
    /*! \fn void filePlay()
     *  \brief Play/Pause
     */
    void filePlay();
    /*! \fn void fileStop()
     *  \brief Stop playing
     */
    void fileStop();
    /*! \fn void getTotalTime(qint64)
     *  \brief Get new full time
     */
    void getTotalTime(qint64);
    /*! \fn void getCurrentTime(qint64)
     *  \brief Get new actual time
     */
    void getCurrentTime(qint64);
    /*! \fn void loadTrackList()
     *  \brief Load track list
     */
    void loadTrackList();
    /*! \fn void saveTrackList()
     *  \brief Save track list
     */
    void saveTrackList();
    /*! \fn void rootSelect()
     *  \brief Select file tree root.
     */
    void rootSelect();
    /*! \fn void setStateIcon(playState_t state)
     *  \brief Newstate to display using the action icons.
     *  \param state New state from enum.
     */
    void setStateIcon(playState_t state);
protected:
    /*! \fn void closeEvent(QCloseEvent *event)
     *  \brief Window close event handler
     *  \details Track list is saved
     */
    void closeEvent(QCloseEvent *event);
};

#endif //__HAUPT_WND__
